using System;
using System.IO;
using System.Xml.Serialization;

namespace SQLRunnerLib.VersionCheck
{
	/// <summary>
	/// Summary description for SQLVersion.
	/// </summary>
	/// 
	[XmlRoot(Namespace="", IsNullable=false)]
	[Serializable]
	public class SQLRunnerVersion
	{
		
		#region Private Instances

		private AppVersion _version;
		private string _msiurl;
		private string _linkText;

		#endregion
		#region Properties

		[XmlElement()]
		public string LinkText
		{
			get { return _linkText; }
			set { _linkText = value; }
		}

		[XmlElement()]
		public string MsiUrl
		{
			get { return _msiurl; }
			set { _msiurl = value; }
		}

		[XmlElement("Version")]
		public AppVersion Version
		{
			get { return _version; }
			set { _version = value; }
		}

		#endregion
		#region Public Serialize Methods

		public void Serialize(StreamWriter writer)
		{
			using(writer)
			{
				XmlSerializer aSerializer = new XmlSerializer(this.GetType());
				aSerializer.Serialize(writer, this);
			}
		}

		public void Serialize(string fileName)
		{
			Serialize(new StreamWriter(fileName));			
		}

		public static SQLRunnerVersion Deserialize(string fileName)
		{
			FileStream file = new FileStream(fileName, FileMode.Open);
			return Deserialize(new StreamReader(file));
		}

		public static SQLRunnerVersion Deserialize(StreamReader reader)
		{
			SQLRunnerVersion version;
			XmlSerializer aSerializer = new XmlSerializer(typeof(SQLRunnerVersion));
			using (reader)
			{
				version = (SQLRunnerVersion) aSerializer.Deserialize(reader);
				reader.Close();
			}
			return version;
		}
		#endregion

	}
}
